package com.clothing.entity;

import com.clothing.CommonAttributes;
import com.clothing.utils.Utils;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Charles
 * @version 1.0
 * @ClassName: Business
 * @Description: TODO(商家)
 * @date 2018年5月27日 上午10:54:36
 */
@Entity
@Table(name = "business")
public class Business extends BaseEntity {
    /**
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
     */
    private static final long serialVersionUID = 3720529990194401030L;

    private String name;

    private User user;

    private Industry industry;

    private String address;

    private String phone;

    private Double longitude;

    private Double latitude;

    private List<String> banners = new ArrayList<>();

    private List<String> images = new ArrayList<>();

    @NotBlank
    @Column(name = "name", nullable = false)

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user", nullable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "industry", nullable = false)
    public Industry getIndustry() {
        return industry;
    }

    public void setIndustry(Industry industry) {
        this.industry = industry;
    }

    @NotBlank
    @Column(name = "address", nullable = false)
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @NotBlank
    @Column(name = "phone", nullable = false)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @NotNull
    @Column(name = "longitude", nullable = false)
    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    @NotNull
    @Column(name = "latitude", nullable = false)
    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    @ElementCollection
    @CollectionTable(name = "business_banner")
    public List<String> getBanners() {
        return banners;
    }

    public void setBanners(List<String> banners) {
        this.banners = banners;
    }

    @ElementCollection
    @CollectionTable(name = "business_image")
    public List<String> getImages() {
        return images;
    }

    public void setImages(List<String> images) {
        this.images = images;
    }

    /**
     * 完整banner图片地址
     * @return
     */
    @Transient
    public List<String> getFullBanners() {
        if (Utils.isEmpty(banners)) {
            return banners;
        }
        List<String> fullBanners = new ArrayList<>();
        for (String banner : banners) {
            if (!Utils.isEmpty(banners)) {
                fullBanners.add(CommonAttributes.SITE_URL + banner);
            }
        }
        return fullBanners;
    }

    /**
     * 完整商家图片地址
     * @return
     */
    @Transient
    public List<String> getFullImages() {
        if (Utils.isEmpty(images)) {
            return images;
        }
        List<String> fullImages = new ArrayList<>();
        for (String image : images) {
            if (!Utils.isEmpty(image)) {
                fullImages.add(CommonAttributes.SITE_URL + image);
            }
        }
        return fullImages;
    }
}
